package com.food.eat.pojo.bo;

import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;


public class OrderDto implements Delayed {

    /**
     * 订单ID
     */
    private Long orderId;

    /**
     * 截止时间日期 【单位毫秒】
     */
    private Long invalid;

    public OrderDto(Long orderId, Long timeCycle) {
        this.orderId = orderId;
        this.invalid = timeCycle * 1000 + System.currentTimeMillis();
    }


    /**
     * 周期校验，截止时间日期是否达到
     *
     * @param unit the time unit
     * @return
     */
    @Override
    public long getDelay(TimeUnit unit) {
        return invalid - System.currentTimeMillis();
    }


    /**
     * 外来对象做比对
     *
     * @param o the object to be compared.
     * @return
     */
    @Override
    public int compareTo(Delayed o) {
        OrderDto o2 = (OrderDto) o;
        return this.invalid - o2.getInvalid() > 0 ? 1 : -1;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Long getInvalid() {
        return invalid;
    }

    public void setInvalid(Long invalid) {
        this.invalid = invalid;
    }
}
